#ifndef IVSCONTROLLERBASE_H
#define IVSCONTROLLERBASE_H

#include <QObject>
#include <QColor>
#include <QTime>
#include "cv.h"
#include "highgui.h"
#include "ivsmodel.h"

class IVSControllerBase: public QObject
{
    Q_OBJECT

public:
    IVSControllerBase(IVSModel* _ivsModel);
    ~IVSControllerBase();

public slots:
    void updateMaskROI(bool isComplete);
    virtual void run();
    virtual void stop();
protected:
    IVSModel* ivsModel;
    bool isRunning;

    CvCapture* capture;
    IplImage* maskROI;
    int fps;
    int videoPlaySpeedBoost;
    CvSize size;

    bool initialize();
    void release();
    bool initCapture();
    void initCaptureProperty();
    void createROIMask();
    void drawROI(IplImage* img, CvScalar color);
    void setupROI();
    void clearROIMask();
    void applyROIMask(IplImage* img);
    void smartThreshold(IplImage* img, int noBin);
    void findOptimalThreshold(IplImage* img, int noBin, uchar* highTh, uchar* lowTh);

    void showMainImage(IplImage* img, CvScalar lineColor = cvScalar(255), CvScalar fillColor = cvScalar(-40,-40,80));
    void showDebugImage(IplImage* img, const char* name);

    int timeInterval();
    void updateBaseTime();
    bool isCreatedNamedWindow;
    QTime baseTime;

signals:
    void stateChanged(QString, QColor);
};

#endif // IVSCONTROLLERBASE_H
